{include file="public/header" /}
<div class="page">
    <form method="get" name="formSearch" id="formSearch">
        <div class="ds-search-form">
            <dl>
                <dt>商品名称：</dt>
                <dd><input type="text" value="{$Request.get.search_goods_name|default=''}" name="search_goods_name"
                        id="search_goods_name" class="txt"></dd>
            </dl>
            <dl>
                <dt>供应商：</dt>
                <dd><input type="text" value="{$Request.get.store_name|default=''}" name="store_name" id="store_name"
                        class="txt"></dd>
            </dl>
            <dl>
                <dt>分类</dt>
                <select name="search_gc_id1" id="search_gc_id1">
                    <option value="">{$Think.lang.ds_please_choose}</option>
                    {notemtpy name="$class_list"}
                    {foreach $class_list as $key => $val}
                    <option value="{$val.gc_id}" {$Request.param.search_gc_id1==$val.gc_id ? 'selected' : '' }>
                        {$val.gc_name}</option>
                    {/foreach}
                    {/notempty}
                </select>
                <select name="search_gc_id2" id="search_gc_id2">
                    <option value="">{$Think.lang.ds_please_choose}</option>
                </select>
                <select name="search_gc_id3" id="search_gc_id3">
                    <option value="">{$Think.lang.ds_please_choose}</option>
                </select>
            </dl>
            <!-- <dl>
                <dt>分类</dt>
                <dd id="searchgc_td"></dd>
                <input type="hidden" id="choose_gcid" name="choose_gcid" value="0"/>
            </dl> -->
            <div class="btn_group">
                <a href="javascript:document.formSearch.submit();" class="btn "
                    title="{$Think.lang.ds_query}">{$Think.lang.ds_query}</a>
                {if $search_goods_name != '' || $store_name != ''}
                <a href="{:url('Goodproject/edit_band_goods')}" class="btn btn-default"
                    title="{$Think.lang.ds_cancel}">{$Think.lang.ds_cancel}</a>
                {/if}
            </div>
        </div>
        <input type="hidden" value="{$project_id}" name="project_id">
        <input type="hidden" value="" name="export">
    </form>

    <form method="post" name="remark_form" id="remark_form">
        <tfoot>
            <tr class="tfoot">
                <td colspan="2">
                    <input style="margin-left: 11px; margin-top: 18px;line-height: 20px;" type='submit' class="btn"
                        value="导入商品" />
                </td>
            </tr>
            <table class="ds-default-table">
                <input type='hidden' name="project_id" value="{$project_id}" />
                <thead>
                    <tr>
                        <th></th>
                        <th class="w60 align-center">平台货号</th>
                        <th>商品</th>
                        <th>商品名称及规格值</th>
                        <th class=" align-center">分类名称&品牌</th>
                        <th class=" align-center">供应商</th>
                    </tr>
                </thead>
                <tbody>
                    {foreach name="goods_list" item="v" key="key"}
                    <tr>
                        <!-- <td class="w24">
                  <input type="checkbox" class="checkitem" name="goods_commonid[]" value="{$v.goods_commonid}" 
                  <?php echo in_array($v['goods_commonid'],$info) ? 'checked' :''; ?> >
              </td> -->
                        <td class="w24">
                            <input type="checkbox" class="checkitem" name="goods_commonid[]" value="{$v.goods_id}"
                                <?php echo in_array($v['goods_id'],$info) ? 'checked' :''; ?>>
                        </td>
                        <td>{$key+1}</td>
                        <td class="w60 picture">
                            <div class="size-56x56"><span class="thumb size-56x56"><i></i><img
                                        src="{:goods_thumb($v, 240)}"
                                        onload="javascript:ResizeImage(this,56,56);" /></span>
                            </div>
                        </td>
                        <td class="name w270"><span>{$v.goods_name}</span></td>
                        <td>
                            <p>{$v.gc_name}</p>
                            <p class="goods-brand">{$Think.lang.ds_brand}：{$v.brand_name}</p>
                        </td>
                        <td>{$v.store_name}</td>
                    </tr>

                    {/foreach}
                </tbody>

        </tfoot>
        </table>
        {$show_page}
    </form>

</div>
<script type="text/javascript" src="{$Think.ADMIN_SITE_ROOT}/js/jquery.edit.js" charset="utf-8"></script>
<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/jquery.mousewheel.js"></script>
<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js" charset="utf-8"></script>

<script src="{$Think.ADMIN_SITE_ROOT}/js/question.js"></script>
<script type="text/javascript" src="{$Think.ADMIN_SITE_ROOT}/js/jquery.edit.js" charset="utf-8"></script>
<script type="text/javascript">
    //查看详情
    function goods_setting_info_jia(ids_str) {
        _uri = ADMINSITEURL + "/Goods/goods_setting_info?commonid=" + ids_str;
        dsLayerOpen(_uri, '查看详情', '900px', '680px');
    }
    $(function () {
        //商品分类
        init_gcselect({
            $gc_choose_json
        }, {
            $gc_json
        });
        /* AJAX选择品牌 */
        $("#ajax_brand").brandinit();

        $('#dssubmit').click(function () {
            $('#formSearch').submit();
        });

        // 审核批量处理
        $('a[dstype="verify_batch"]').click(function () {
            ids_str = getItems();
            if (ids_str) {
                goods_verify(ids_str);
            }
        });
        // 违规下架批量处理
        $('a[dstype="lockup_batch"]').click(function () {
            ids_str = getItems();
            if (ids_str) {
                goods_lockup(ids_str);
            }
        });

        // ajax获取商品列表
        $('i[dstype="ajaxGoodsList"]').click(
            function () {

                var status = $(this).attr("status");
                if (status == 'open') {
                    $(this).attr('status', 'close');
                    $(this).removeClass('icon-jia').addClass('icon-jian');
                    var _parenttr = $(this).parents('tr');
                    var _commonid = $(this).attr('data-comminid');
                    var _div = _parenttr.next().find('.dssc-goods-sku');
                    if (_div.html() == '') {
                        $.getJSON('{:url("Goods/get_goods_list_ajax")}', {
                            commonid: _commonid
                        }, function (date) {
                            if (date != 'false') {
                                var _ul = $('<ul class="dssc-goods-sku-list"></ul>');
                                var res = eval('(' + date + ')');
                                for (var i = 0; i < res.length; i++) {
                                    $('<li><div class="goods-thumb" title="{$Think.lang.goods_serial}：' +
                                        res[i].goods_serial + '"><a href="' + res[i].url +
                                        '" target="_blank"><image src="' + res[i].goods_image +
                                        '" ></a></div>' + res[i].goods_spec +
                                        '<div class="goods-price">{$Think.lang.goods_price}：<em title="￥' +
                                        res[i].goods_price + '">￥' + res[i].goods_price +
                                        '</em></div><div class="goods-storage">{$Think.lang.goods_storage}：<em title="' +
                                        res[i].goods_storage + '">' + res[i].goods_storage +
                                        '</em></div><a href="' + res[i].url +
                                        '" target="_blank" class="dssc-btn-mini">{$Think.lang.show_goods_detail}</a></li>'
                                        ).appendTo(_ul);
                                    _ul.appendTo(_div);
                                    _parenttr.next().show();
                                }

                                // 计算div的宽度
                                _div.css('width', document.body.clientWidth - 54);

                                //                        _div.perfectScrollbar();
                            }
                        });
                    } else {
                        _parenttr.next().show()
                    }
                } else {
                    $(this).attr('status', 'open');
                    $(this).removeClass('icon-jian').addClass('icon-jia');
                    $(this).parents('tr').next().hide();
                }

            }
        );
    });

    // 获得选中ID
    function getItems() {
        /* 获取选中的项 */
        var items = '';
        $('.checkitem:checked').each(function () {
            items += this.value + ',';
        });
        if (items != '') {
            items = items.substr(0, (items.length - 1));
        } else {
            layer.alert('{$Think.lang.please_select_input}', {
                icon: 2
            })
        }
        return items;
    }

    // 商品下架
    function goods_lockup(ids_str) {
        _uri = ADMINSITEURL + "/Goods/goods_lockup?commonid=" + ids_str;
        dsLayerOpen(_uri, '{$Think.lang.goods_index_lock_reason}', '400px', '200px');
    }

    // 商品审核
    function goods_verify(ids_str) {
        _uri = ADMINSITEURL + "/Goods/goods_verify?commonid=" + ids_str;
        dsLayerOpen(_uri, '{$Think.lang.goods_verify}', '400px', '200px');
    }

    //商品设置平台价格
    function goods_setting_price(ids_str) {
        _uri = ADMINSITEURL + "/Product/goods_setting_price?commonid=" + ids_str;
        dsLayerOpen(_uri, '{$Think.lang.ds_setting_price}', '1200px', '800px');
    }

    //商品设置教程
    function goods_setting_course(ids_str) {
        _uri = ADMINSITEURL + "/Goods/goods_setting_course?commonid=" + ids_str;
        dsLayerOpen(_uri, '{$Think.lang.ds_setting_price}', '400px', '400px');
    }

    function submit_delete(ids_str) {
        _uri = ADMINSITEURL + "/Goods/goods_del.html?common_id=" + ids_str;
        dsLayerConfirm(_uri, '{$Think.lang.ds_ensure_del}');
    }

    function getGcId1(gc_id1, select_id) {
        var select_od = select_id;
        $.ajax({
            type: "GET",
            contentType: "application/json;charset=UTF-8",
            url: ADMINSITEURL + "/Question/getClass.html?gc_id=" + gc_id1,
            success: function (result) {
                result = JSON.parse(result);
                var html = '<option value="">选择分类</option>';
                for (var i = 0; i < result.length; i++) {
                    if (result[i].gc_id == select_id) {
                        html += '<option selected value="' + result[i].gc_id + '">' + result[i].gc_name +
                            '</option>'
                    } else {
                        html += '<option value="' + result[i].gc_id + '">' + result[i].gc_name + '</option>'
                    }
                }
                $('#search_gc_id2').html(html)
            },
            //请求失败，包含具体的错误信息
            error: function (e) {
                console.log(e.status);
                console.log(e.responseText);
            }
        });
    }

    function getGcId2(gc_id1, select_id) {
        $.ajax({
            type: "GET",
            contentType: "application/json;charset=UTF-8",
            url: ADMINSITEURL + "/Question/getClass.html?gc_id=" + gc_id1,
            success: function (result) {
                result = JSON.parse(result);
                var html = '<option value="">选择分类</option>';
                for (var i = 0; i < result.length; i++) {
                    if (result[i].gc_id == select_id) {
                        html += '<option selected value="' + result[i].gc_id + '">' + result[i].gc_name +
                            '</option>'
                    } else {
                        html += '<option value="' + result[i].gc_id + '">' + result[i].gc_name + '</option>'
                    }
                }
                $('#search_gc_id3').html(html)
            },
            //请求失败，包含具体的错误信息
            error: function (e) {
                console.log(e.status);
                console.log(e.responseText);
            }
        });
    }
    //获取下级分类
    $('#search_gc_id1').on('change', function () {
        var gc_id1 = $(this).val();
        getGcId1(gc_id1)
    })

    $('#search_gc_id2').on('change', function () {
        var gc_id2 = $(this).val();
        getGcId2(gc_id2)
    })
</script>
{if $Request.param.search_gc_id1}
<script>
    // 编辑初始化，处理分类选中的问题
    var gc_id1 = '{$Request.param.search_gc_id1}';
    var gc_id2 = '{$Request.param.search_gc_id2}';
    var gc_id3 = '{$Request.param.search_gc_id3}';
    getGcId1(gc_id1, gc_id2)
    getGcId2(gc_id2, gc_id3)
</script>
{/if}